package com.example.activitidemo;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 基础返回对象.
 *
 * @author 倪颖强
 */
@Data
@Builder
@EqualsAndHashCode(callSuper = false)
public class RespBase<T> {
    private int code;

    private String message;

    private T data;

    /**
     * 成功.
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> RespBase<T> success(T data) {
        return RespBase.<T>builder()
                .code(0)
                .message("")
                .data(data)
                .build();
    }

    /**
     * 失败.
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> RespBase<T> fail(int code, String message) {
        return RespBase.<T>builder()
                .code(code)
                .message(message)
                .build();
    }
}
